var o, e = require, t = module, n = exports, i = this && this.__extends || (o = function(t, e) {
    return (o = Object.setPrototypeOf || {
        __proto__: []
    } instanceof Array && function(t, e) {
        t.__proto__ = e;
    } || function(t, e) {
        for (var i in e) e.hasOwnProperty(i) && (t[i] = e[i]);
    })(t, e);
}, function(t, e) {
    function i() {
        this.constructor = t;
    }
    o(t, e), t.prototype = null === e ? Object.create(e) : (i.prototype = e.prototype, 
    new i());
}), a = this && this.__decorate || function(t, e, i, n) {
    var r, s = arguments.length, a = s < 3 ? e : null === n ? n = Object.getOwnPropertyDescriptor(e, i) : n;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) a = Reflect.decorate(t, e, i, n); else for (var o = t.length - 1; 0 <= o; o--) (r = t[o]) && (a = (s < 3 ? r(a) : 3 < s ? r(e, i, a) : r(e, i)) || a);
    return 3 < s && a && Object.defineProperty(e, i, a), a;
};

Object.defineProperty(n, "__esModule", {
    value: !0
});

var r = e("SkinView"), s = e("Global"), c = e("PetManager"), l = e("EquipManager"), d = e("GameConfig"), u = e("GameData"), p = e("LoadManager"), h = cc._decorator, f = h.ccclass, g = h.property, m = function(e) {
    function t() {
        var t = null !== e && e.apply(this, arguments) || this;
        return t.toggle = null, t.sprite = null, t.nameLabel = null, t.rankLabel = null, 
        t.skin = null, t.arm = null, t.star = null, t.__itemID = 0, t.type = r.SkinItemType.PERSON, 
        t.data = null, t;
    }
    return i(t, e), t.prototype.start = function() {}, t.prototype.init = function(t) {
        switch ((this.data = t).type) {
          case r.SkinItemType.PERSON:
            this.initPerson(t);
            break;

          case r.SkinItemType.GUN:
            this.initGun(t);
            break;

          case r.SkinItemType.PET:
            this.initPet(t);
            break;

          case r.SkinItemType.EQUIP:
            this.initEquip(t);
            break;

          case r.SkinItemType.EGG:
            this.initEgg(t);
            break;

          default:
            this.initGun(t);
        }
    }, t.prototype.initPerson = function(e) {
        var t = this;
        if (this.type = r.SkinItemType.PERSON, this.skin.active = !0, this.arm.active = !1, 
        this.nameLabel.node.y = 22, !isNaN(e.rank)) {
            var i = s.G.personModelList.filter(function(t) {
                return t.id == e.rank;
            });
            if (0 < i.length) if (this.nameLabel.string = i[0].m, this.rankLabel.string = (e.rank + 1).toString(), 
            this.star.parent.childrenCount < i[0].s) for (;this.star.parent.childrenCount < i[0].s; ) this.star.parent.addChild(cc.instantiate(this.star)); else if (this.star.parent.childrenCount > i[0].s) for (;this.star.parent.childrenCount > i[0].s; ) this.star.parent.removeChild(this.star.parent.children[this.star.parent.childrenCount - 1]);
            p.default.getInstance().loadSpriteFrame({
                url: "image/skin/" + e.rank,
                sprite: this.sprite,
                success: function() {
                    t.sprite.node.scale = 1;
                }
            }), e.rank == u.GD.personIdx ? this.toggle.isChecked = !0 : this.toggle.isChecked = !1;
        }
    }, t.prototype.initGun = function(t) {
        var e = this;
        this.type = r.SkinItemType.GUN, this.skin.active = !1, this.arm.active = !0, this.nameLabel.node.y = -20, 
        3e3 <= t.rank ? (this.nameLabel.string = s.G.getGunModel(t.rank).m, this.rankLabel.string = "-", 
        p.default.getInstance().loadSpriteFrame({
            url: "texture/armOlympic/" + t.rank,
            sprite: this.sprite,
            success: function() {
                e.sprite.node.scale = .5;
            }
        }), t.rank == u.GD.gunIdx ? this.toggle.isChecked = !0 : this.toggle.isChecked = !1, 
        GA.Info.underCheck && d.GC.isDebug || (this.sprite.node.color = cc.Color.WHITE)) : isNaN(t.rank) || (this.nameLabel.string = s.G.getGunModel(t.rank).m, 
        this.rankLabel.string = (t.rank + 1).toString(), p.default.getInstance().loadSpriteFrame({
            url: "image/arm/" + s.G.getIdxByRank(t.rank),
            sprite: this.sprite,
            success: function() {
                e.sprite.node.scale = .5;
            }
        }), t.rank == u.GD.gunIdx ? this.toggle.isChecked = !0 : this.toggle.isChecked = !1, 
        GA.Info.underCheck && d.GC.isDebug || (t.rank > u.GD.topRank ? this.sprite.node.color = cc.Color.BLACK : this.sprite.node.color = cc.Color.WHITE));
    }, t.prototype.initPet = function(t) {
        var e = this;
        this.type = r.SkinItemType.PET, this.skin.active = !0, this.arm.active = !1;
        var i = c.default.getInstance().getConfig(t.rank), n = c.default.getInstance().getRealData(t.rank);
        if (i.id < 200 && 100 <= i.id && !n.has ? (this.nameLabel.string = "机甲暴龙蛋", p.default.getInstance().loadSpriteFrame({
            url: "image/skin3/" + i.id,
            sprite: this.sprite,
            success: function() {
                e.sprite.node.scale = 1;
            }
        })) : (this.nameLabel.string = i.m, p.default.getInstance().loadSpriteFrame({
            url: "image/skin3/" + t.rank,
            sprite: this.sprite,
            success: function() {
                e.sprite.node.scale = 1;
            }
        })), this.nameLabel.node.y = 22, this.rankLabel.string = (t.rank + 1).toString(), 
        this.star.parent.childrenCount < d.GC.petModelList[t.rank].s) for (;this.star.parent.childrenCount < d.GC.petModelList[t.rank].s; ) this.star.parent.addChild(cc.instantiate(this.star)); else if (this.star.parent.childrenCount > d.GC.petModelList[t.rank].s) for (;this.star.parent.childrenCount > d.GC.petModelList[t.rank].s; ) this.star.parent.removeChild(this.star.parent.children[this.star.parent.childrenCount - 1]);
        t.rank == u.GD.petDataIdx ? this.toggle.isChecked = !0 : this.toggle.isChecked = !1;
    }, t.prototype.initEquip = function(t) {
        var e = this;
        this.type = r.SkinItemType.EQUIP, this.skin.active = !0, this.arm.active = !1, this.nameLabel.node.y = 22, 
        this.rankLabel.string = (t.rank + 1).toString();
        var i = l.default.getInstance().getConfig(t.rank);
        if (i) {
            this.nameLabel.string = i.name;
            var n = l.default.getInstance().getData(t.rank), n = n ? n.form : 0;
            if (p.default.getInstance().loadSpriteFrame({
                url: "image/equip/" + i.pre + (n + 1) + i.suf,
                sprite: this.sprite,
                success: function() {
                    e.sprite.node.scale = 1;
                }
            }), this.star.parent.childrenCount < i.s) for (;this.star.parent.childrenCount < i.s; ) this.star.parent.addChild(cc.instantiate(this.star)); else if (this.star.parent.childrenCount > i.s) for (;this.star.parent.childrenCount > i.s; ) this.star.parent.removeChild(this.star.parent.children[this.star.parent.childrenCount - 1]);
        }
        t.rank == u.GD.petDataIdx ? this.toggle.isChecked = !0 : this.toggle.isChecked = !1;
    }, t.prototype.initEgg = function(e) {
        var t = this;
        if (this.type = r.SkinItemType.EGG, this.skin.active = !0, this.arm.active = !1, 
        this.nameLabel.node.y = 22, !isNaN(e.rank)) {
            var i = s.G.eggPersonModelList.filter(function(t) {
                return t.id == e.rank;
            });
            if (0 < i.length) if (this.nameLabel.string = i[0].m, this.rankLabel.string = (e.rank + 1).toString(), 
            this.star.parent.childrenCount < i[0].s) for (;this.star.parent.childrenCount < i[0].s; ) this.star.parent.addChild(cc.instantiate(this.star)); else if (this.star.parent.childrenCount > i[0].s) for (;this.star.parent.childrenCount > i[0].s; ) this.star.parent.removeChild(this.star.parent.children[this.star.parent.childrenCount - 1]);
            p.default.getInstance().loadSpriteFrame({
                url: "image/skin2/" + e.rank,
                sprite: this.sprite,
                success: function() {
                    t.sprite.node.scale = 1;
                }
            }), e.rank == s.G.getEggIdx(u.GD.personIdx, 2) ? this.toggle.isChecked = !0 : this.toggle.isChecked = !1;
        }
    }, a([ g(cc.Toggle) ], t.prototype, "toggle", void 0), a([ g(cc.Sprite) ], t.prototype, "sprite", void 0), 
    a([ g(cc.Label) ], t.prototype, "nameLabel", void 0), a([ g(cc.Label) ], t.prototype, "rankLabel", void 0), 
    a([ g(cc.Node) ], t.prototype, "skin", void 0), a([ g(cc.Node) ], t.prototype, "arm", void 0), 
    a([ g(cc.Node) ], t.prototype, "star", void 0), a([ f ], t);
}(cc.Component);

n.default = m;